package com.ssy.jt808.gateway.sdk.terminal.message.alarm;

import com.ssy.jt808.gateway.sdk.terminal.constant.AlarmMessageEnum;
import com.ssy.jt808.gateway.sdk.terminal.message.TerminalMessageBase;
import com.ssy.jt808.gateway.sdk.terminal.pojo.info.alarm.TerminalAlarmInfo;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zeno
 */
@Data
@NoArgsConstructor
public class TerminalAlarmMessage extends TerminalMessageBase<AlarmMessageEnum>{

  private List<TerminalAlarmInfo> alarmInfos;

  public void addAlarmInfo( TerminalAlarmInfo alarmInfo ){

    if( !alarmInfo.existsAlarm() ){
      // 如果没有报警信息，则不入到报警列表中。
      return;
    }

    if( CollectionUtils.isEmpty(alarmInfos) ){
      this.alarmInfos = new ArrayList<>();
    }

    alarmInfos.add(alarmInfo);
  }

  /** 消息类型 */
  @Override
  public AlarmMessageEnum type(){
    return AlarmMessageEnum.Terminal;
  }
}
